package com.ybt.context.util.pool;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.ruleengine.context.IContextProperty;
import com.ruleengine.context.IWorkflowConext;
import com.ruleengine.context.IWorkflowContextConstants;

public class YBTContextPool {
    private Map<String, IWorkflowConext> poolMap;
    private volatile static YBTContextPool pool;

    private YBTContextPool() {
        poolMap = new ConcurrentHashMap<String, IWorkflowConext>();
    }

    public static YBTContextPool getInstance() {
        if (pool == null) {
            synchronized (YBTContextPool.class) {
                if (pool == null) {
                    pool = new YBTContextPool();
                }
            }
        }
        return pool;
    }

    public IWorkflowConext getContext(String excuteId) {
        return poolMap.get(excuteId);
    }

    public void setContext(IWorkflowConext context) {
        IContextProperty<String> p = context
                .getContextProperty(IWorkflowContextConstants.WORKFLOW_EXECUTE_ID);
        String excuteId = p.getValue();
        poolMap.put(excuteId, context);
    }

}
